import React, { Component, useState } from 'react'
import { Navigate } from 'react-router-dom'

export default function Home() {
  const [sum, setSum] = useState(1)

  return (
    <div>
      <h3>我是Home组件</h3>
      {/* 根据sum的值决定是否切换视图 */}
      {sum === 2 ? <Navigate to="/about" replace={true}></Navigate> : <h4>当前sum的值是：{sum}</h4>}
      <button onClick={() => setSum(2)}>点我将sum变为{2}</button>
    </div>
  )
}
